package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2022/3/9 10:26
 * @description：https://leetcode-cn.com/problems/corporate-flight-bookings/
 */
public class 航班预订统计 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(Arrays.toString(solution.corpFlightBookings(new int[][]{{1, 2, 10}, {2, 3, 20}, {2, 5, 25}}, 5)));
    }

    class Solution {
        public int[] corpFlightBookings(int[][] bookings, int n) {
            int[] c = new int[n + 1];
            for (int[] booking : bookings) {
                int l = booking[0] - 1, r = booking[1] - 1, v = booking[2];
                c[l] += v;
                c[r + 1] -= v;
            }
            int[] ans = new int[n];
            ans[0] = c[0];
            for (int i = 1; i < n; i++) {
                ans[i] = ans[i - 1] + c[i];
            }
            return ans;
        }
    }

}
